package com.hj.controller;

import android.app.Activity;
import android.util.Log;

import java.util.ArrayList;

/**
 * Created by hp on 2018/4/26.
 */

public class Controller {
    private static ControlObservable observable;
    private static final String PackageName = "com.action.";

    public Controller() {
    }

    public static void sendNotification(Activity context, String command, ControllerParamBean params, ObserverCallback callback) {
        if(observable != null) {
            Log.d("Controller", "发送消息：指令：" + command);
            observable.execute(context, command, params, callback);
        }
    }

    public static void registerObserver(ControlObserver observer) {
        if(observable == null) {
            observable = new ControlObservable();
        }

        observable.registerObserver(observer);
    }

    public static void unregisterObserver(ControlObserver observer) {
        if(observable != null) {
            observable.unregisterObserver(observer);
        }
    }

    public static void unregisterAll() {
        if(observable != null) {
            observable.unregisterAll();
        }
    }

    static class ControlObservable extends Observable<ControlObserver> {
        ControlObservable() {
        }

        public void execute(Activity context, String command, ControllerParamBean params, ObserverCallback callback) {
            ArrayList var5 = this.mObservers;
            synchronized(this.mObservers) {
                for(int i = 0; i < this.mObservers.size(); ++i) {
                    this.mObservers.get(i).execute(context, command, params, callback);
                }

            }
        }
    }
}
